﻿using System;
using System.Web.Mvc;
using System.Web.Routing;
using AutoMapper;
using ilgolosone.Shared;
using ilgolosone.Shared.IoC;
using ilgolosone.UI.Mappers;

namespace ilgolosone.UI
{
    // For instructions on enabling IIS6 or IIS7 classic mode, 
    // visit http://go.microsoft.com/?LinkId=9394801

    public class IlGolosoneMvc : System.Web.HttpApplication
    {
        private static void RegisterRoutes(RouteCollection routes)
        {
            routes.IgnoreRoute("{resource}.axd/{*pathInfo}");

            routes.MapRoute(
                "Default",                                              // Route name
                "{controller}/{action}/{id}",                           // URL with parameters
                new { controller = "Home", action = "Index", id = "" }  // Parameter defaults
            );

        }

        private static void RegisterMappers()
        {
            Mapper.Initialize(x => x.AddProfile<MapperRegistry>());
        }

        protected void Application_Start(object sender, EventArgs e)
        {
            Bootstrapper.Initialize();
            var controllerFactory = DependencyResolver.Resolve<IControllerFactory>();
            ControllerBuilder.Current.SetControllerFactory(controllerFactory);
            RegisterRoutes(RouteTable.Routes);
            RegisterMappers();

            // Per attivare la profilazione su NHProf...
            // HibernatingRhinos.NHibernate.Profiler.Appender.NHibernateProfiler.Initialize();
        }

        protected void Application_End(object sender, EventArgs e)
        {
            DependencyResolver.Release();
        }
    }
}